<template>
  <div class="app-container">
    <el-form
      :model="memberRule"
      :rules="rules"
      ref="memberRule"
      label-position="right"
      label-width="120px" style="margin-left:30px;"
    >
      <el-row :gutter="24" style="margin-bottom: 60px;">
        <div>
          <span>会员积分规则配置</span>
          <el-divider></el-divider>
        </div>
        <el-form-item label="会员注册" prop="register">
          <el-input-number v-model="memberRule.register" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员注册送积分数量</span>
        </el-form-item>
        <el-form-item label="每日登陆" prop="login">
          <el-input-number v-model="memberRule.login" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员每天第一次登陆送积分数量</span>
        </el-form-item>
        <el-form-item label="会员签到" prop="sign">
          <el-input-number v-model="memberRule.sign" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员签到送积分数量</span>
        </el-form-item>
        <el-form-item label="订单评论" prop="orderEvaluate">
          <el-input-number v-model="memberRule.orderEvaluate" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员评论商品送积分数量</span>
        </el-form-item>
        <el-form-item label="会员购物" prop="orderBuy">
          <el-input-number v-model="memberRule.orderBuy" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员购物时送积分的比例。如设定10，则表示会员消费200元时，送积分：200/10=20，即送20积分</span>
        </el-form-item>
        <el-form-item label="购物送值上限" prop="orderMax">
          <el-input-number v-model="memberRule.orderMax" :min="1" :max="999999999" :precision="0"></el-input-number>
          <span class="form-word-hint">会员购物时送积分的上限。如设定100，会员消费金额根据上述规则换算后需要送出105积分，则取上限值只送出100积分</span>
        </el-form-item>
        <el-form-item label="使用状态" prop="state">
          <el-select v-model="memberRule.state + ''" class="filter-item" placeholder="请选择" @change="refreshStatus">
            <el-option v-for="(item,index) in optStateValues" :label="item.name" :key="index" :value="item.value" />
          </el-select>
        </el-form-item>
      </el-row>

      <el-row :gutter="24">
        <div class="fixed-bottom-20">
          <el-button type="primary" @click="submitForm('memberRule')">立即提交</el-button>
        </div>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { intvalueMember, intvalueUpdateMember} from '@/api/member'
import { getCodeManager,codeToArray } from '@/api/all'
export default {
  name: "intvalue",
  data() {
    return {
      memberRule: {},
      optStateValues: [],
      rules: {
        register: [{ required: true, message: '请填写会员注册送积分数量', trigger: 'blur' }],
        login: [{ required: true, message: '请填写每日登陆送的积分', trigger: 'blur' }],
        sign: [{ required: true, message: '请填写会员签到送的积分', trigger: 'blur' }],
        orderEvaluate: [{ required: true, message: '请填写订单评论送的积分', trigger: 'blur' }],
        orderBuy: [{ required: true, message: '请填写会议购物送的积分', trigger: 'blur' }],
        orderMax: [{ required: true, message: '请填写购物送值上限', trigger: 'blur' }],
        state: [{ required: true, message: '请选择使用状态', trigger: 'change' }]
      },
    };
  },
  created() {
    getCodeManager('MEMBER_RULE_STATE', () => {
      this.optStateValues = codeToArray('MEMBER_RULE_STATE');
    })
    intvalueMember().then((res) => {
      this.memberRule = res.data.data.memberRule
    })
  },
  methods: {
    submitForm(memberRule) {
      this.$refs[memberRule].validate((valid) => {
        if (valid) {
          intvalueUpdateMember(this.memberRule).then(res => {
            if(!res.data.success) {
              Message.error(res.data.message);
              return;
            }
            Message.success('操作成功')
            return;
          })
        }
      });
    },
    refreshStatus(val){
      this.memberRule.state = val + '';
    }
  }

}
</script>

<style>
  
</style>
